{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "队列是一种操作受限制的数据结构：只允许在队尾插入元素，在队头删除元素。\n",
    "\n",
    "Python 没有专门的队列类型，但可以使用 `deque` 来模拟队列，`append` 相当于入队，`popleft` 相当于出队。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "from collections import deque\n",
    "\n",
    "# 初始化队列\n",
    "q = deque()\n",
    "\n",
    "# 向队尾插入元素\n",
    "q.append(10)\n",
    "q.append(20)\n",
    "q.append(30)\n",
    "\n",
    "# 是否为空，输出：False\n",
    "print(len(q) == 0)\n",
    "\n",
    "# 大小，输出：3\n",
    "print(len(q))\n",
    "\n",
    "# 获取队头元素，不出队，输出：10\n",
    "print(q[0])\n",
    "\n",
    "# 队头元素出队\n",
    "q.popleft()\n",
    "\n",
    "# 新的队头元素，输出：20\n",
    "print(q[0])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "science39",
   "language": "python",
   "name": "science39"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
